/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 4, 2013  9:54:16 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces.servlet
 * File Name : GetAppHosts.java
 * TODO
 */
package com.tis.interfaces.servlet;

import java.io.IOException;
import java.io.Serializable;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.hibernate.HibernateException;
import promis.utility.CommonService;
import sap.business.enumeration.InterfaceSecurity;
import com.tis.utilitys.PropertiesUtility;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 4, 2013 : 9:54:16 AM 
 * CreateBy=Chatree Siangklom
 * TODO
 */
public class GetAppHosts extends SimpleTagSupport implements Serializable{

	private String code;	
	private String isActive;	
	private String client;
	
	/**
	 * @param code the code to set
	 * Date =Nov 4, 2013 : 10:31:12 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @param isActive the isActive to set
	 * Date =Nov 4, 2013 : 10:31:12 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	public void setIsActive(String isActive) {
		this.isActive = isActive;
	}

	/**
	 * @param client the client to set
	 * Date =Nov 4, 2013 : 10:31:12 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	public void setClient(String client) {
		this.client = client;
	}

	/**
	 * 
	 * Date =Nov 4, 2013 : 9:54:55 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	private static final long serialVersionUID = 1L;
	
	/** (Javadoc)
	 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
	 * Date =Nov 4, 2013 : 9:55:18 AM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public void doTag() throws JspException, IOException {
		super.doTag();
		
		System.out.println("code=" + code + "//isActive=" + isActive + "//client=" + client);
		
		JspWriter out = getJspContext().getOut();
		try{
			
			JspFragment f = getJspBody();
			if(f != null) 
				f.invoke(out);
			
			PropertiesUtility prop = new PropertiesUtility();
			String url = prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.protocol()) + "://" + prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.host()) + ":" + prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.port()) + "/"+ prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.ContextName());
			 
			if(CommonService.IsNullRString(code).equals("PMS_APPS_INTERFACE_HOST"))
				out.print(url);
			else if(CommonService.IsNullRString(code).equals("AUTHEN_KEY"))
				out.print(prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.user()) + "=" + prop.GetConfigInterfaceSecurityValue(InterfaceSecurity.password()));
			else 
				out.print("");
			
		}catch(IOException ex){
			ex.printStackTrace();
			throw new JspException("Error in NameTagHandler tag", ex);
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new JspException("Error in HibernateException tag", e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new JspException("Error in Exception tag", e);
		}
	}

}
